//
//  SelectMediaCell.m
//  Behing
//
//  Created by Lj on 2017/10/20.
//  Copyright © 2017年 lj. All rights reserved.
//

#import "SelectMediaCell.h"
#import "BHProgressView.h"

@interface SelectMediaCell ()

@property (nonatomic, strong) UIButton *deleteButton;
@property (nonatomic, strong) UILabel *promptLabel;
@property (nonatomic, strong) BHProgressView *progressView;

@end

@implementation SelectMediaCell

- (UIButton *)deleteButton {
    if (_deleteButton == nil) {
        _deleteButton = [[UIButton alloc]initWithFrame:CGRectMake(CGRectGetWidth(self.bounds) - 20, 0, 20, 20)];
        [_deleteButton setImage:[UIImage imageNamed:@"icon_delete"] forState:UIControlStateNormal];
        [_deleteButton addTarget:self action:@selector(deleteClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:_deleteButton];
    }
    return _deleteButton;
}

- (UILabel *)promptLabel {
    if (_promptLabel == nil) {
        _promptLabel = [[UILabel alloc]initWithFrame:CGRectZero];
        _promptLabel.frame = CGRectMake(0, CGRectGetHeight(self.image.bounds) - 20, CGRectGetWidth(self.image.bounds), 20);
        _promptLabel.text = @"上传成功";
        _promptLabel.font = BHFont_Size_12;
        _promptLabel.textColor = [UIColor whiteColor];
        _promptLabel.textAlignment = NSTextAlignmentCenter;
        _promptLabel.backgroundColor = [UIColor colorWithWhite:0.f alpha:0.3];
        [self.image addSubview:_promptLabel];
    }
    return _promptLabel;
}

- (BHProgressView *)progressView {
    if (_progressView == nil) {
        _progressView = [[BHProgressView alloc]initWithFrame:CGRectMake((CGRectGetWidth(self.image.bounds) - 30)/2, (CGRectGetHeight(self.image.bounds) - 30)/2, 30, 30)];
        _progressView.backgroundColor = [UIColor clearColor];
        _progressView.progressType = TurnRingProgressType;
        [self.image addSubview:_progressView];
    }
    return _progressView;
}

#pragma mark - initView
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setUpUI];
    }
    return self;
}

- (void)setUpUI {
    self.image = [[UIImageView alloc]initWithFrame:self.bounds];
    self.image.layer.cornerRadius = 3;
    self.image.clipsToBounds = YES;
    self.image.userInteractionEnabled = YES;
//    self.image.contentMode = UIViewContentModeScaleAspectFill;
    self.image.contentMode = UIViewContentModeScaleToFill;
    [self.contentView addSubview:self.image];    
}

- (void)setIsDelete:(BOOL)isDelete {
    _isDelete = isDelete;
    self.deleteButton.hidden = !isDelete;
    if (isDelete) {
        self.image.frame = CGRectMake(0, 10, CGRectGetWidth(self.bounds) - 10, CGRectGetHeight(self.bounds) - 10);
    }else {
        self.image.frame = self.bounds;
    }
}

- (void)setIsImplement:(BOOL)isImplement {
    if (_isDelete && isImplement) {
        self.deleteButton.hidden = YES;
        self.promptLabel.hidden = YES;
    }else {
        self.deleteButton.hidden = NO;
        self.promptLabel.hidden = YES;
    }
}

- (void)setIsPrompt:(BOOL)isPrompt {
    self.promptLabel.hidden = !isPrompt;
}

- (void)accordingAnimation {
    [self.progressView accordingAnimation];
}

- (void)hideAnimation {
    [self.progressView hideAnimation];
    [self.progressView removeFromSuperview];
    self.progressView = nil;
}

#pragma mark - 按钮
- (void)deleteClick:(UIButton *)sender {
    self.deleteBlock == nil ? : self.deleteBlock();
}

@end
